package com.example.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.example.demo.model.Order;
import com.example.demo.repository.OrderRepository;
import com.example.demo.service.OrderService;

@Service
public class OrderServiceImpl extends BaseServiceImpl<Order> implements OrderService {
	@Autowired
	private OrderRepository orderRepository;

	@Override
	public void saveOrUpdate(Order entity) throws Exception {
		long currentTimeMillis = System.currentTimeMillis();
		entity.setCreate(currentTimeMillis+"");
		entity.setIsDelete("0");
		if (StringUtils.isEmpty(entity.getId())) {
			orderRepository.save(entity);
		} else {
			updateNotNull(entity);
		}
	}

	@Override
	public void deleteLogic(Object key) throws Exception {
		Order entity = orderRepository.findById(key.toString()).get();
		if (entity == null) {
			throw new Exception("数据不存在");
		}
		entity.setIsDelete("1");
		orderRepository.save(entity);
	}

}
